package loader.persister;

import java.util.HashMap;

import loader.parser.adapter.SiteAdapter;

import org.dom4j.Element;

public class CityPersister extends Persister {
	
	private int cityCount = 0;
	private HashMap<String, String> city;

	public CityPersister() {
	}

	public CityPersister(SiteAdapter adapter) {
		this.adapter = adapter;
	}

	@Override
	public void clear() {
		this.clear("city");
		this.cityCount = 0;
	}

	@Override
	public void addProperty(Element ele) {
		city.put(getAdapter().getProperName("d"+ele.getName().trim()), ele
				.getStringValue().trim());
	}

	@Override
	public void detectNewObject(Element ele) {
		if (getAdapter().isNewCity(ele.getName())) {
			if (city != null) {
				city.put("id", this.cityCount + "");
				this.persist("city", city);
				this.cityCount++;
			}
			city = new HashMap<String, String>();
		} 
	}
}
